package com.tarena.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.tarena.domain.Dept;
import com.tarena.domain.Emp;
import com.tarena.util.HbnUtil;

public class EmpDao {
	/**
	 * @InsertDept
	 * @infomation Insert a employee according to the name.
	 * @param name
	 */
	public void insertEmp(Emp emp){
		Session s = HbnUtil.getSession();
		s.beginTransaction();
		s.save(emp);
		s.getTransaction().commit();
		s.close();
	}
	
	/**
	 * @class Get a employee by its deptId.
	 * @param deptId
	 * @return Emp
	 */
	public Emp getEmpById(Integer empId){
		Session s = HbnUtil.getSession();
		Emp emp = (Emp)s.get(Emp.class, empId);
		s.close();
		return emp;
	}
	
	/**
	 * @class delete a employee by the deptId.
	 * @param deptId
	 */
	public void deleteEmpById(Integer empId){
		Session s = HbnUtil.getSession();
		s.beginTransaction();
		s.delete(s.get(Emp.class,empId));
		s.getTransaction().commit();
		s.close();
	}
	
	/**
	 * @ Get all employee .
	 * @return list
	 */
	public List<Dept> getAllEmp(){
		Session s = HbnUtil.getSession();
		Query query = s.getNamedQuery("findAllEmp");
		List<Dept> empList = query.list();
		s.close();		
		return empList;
	}
	
}
